package com.example.demo.service.impl;

import com.example.demo.dataobject.Complication;
import com.example.demo.dataobject.UserInfo;
import com.example.demo.repository.ComplicationRepository;
import com.example.demo.repository.UserInfoRepository;
import com.example.demo.service.ComplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ComplicationServiceImpl implements ComplicationService {

    @Autowired
    private UserInfoRepository userInfoRepository;

    @Autowired
    private ComplicationRepository complicationRepository;

    @Override
    public boolean save(Complication complication) {
        Complication result = complicationRepository.save(complication);
        if(result!=null){
            return true;
        }

        System.out.println();
        return false;
    }

    @Override
    public Complication findByTelephone(String telephone) {
        UserInfo userInfo = userInfoRepository.findByTelephone(telephone);
        Complication complication = complicationRepository.findByUserId(userInfo.getId());
        return complication;
    }
}
